package cn.stylefeng.guns.modular.system.controller;

import cn.stylefeng.guns.core.common.constant.factory.PageFactory;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import cn.stylefeng.guns.modular.system.dto.DeviceTotalQuery;
import cn.stylefeng.guns.modular.system.model.DeviceTotal;
import cn.stylefeng.guns.modular.system.model.OperationLog;
import cn.stylefeng.guns.modular.system.service.IDeviceTotalService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.plugins.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 设备统计表控制器
 *
 * @author fengshuonan
 * @Date 2018-11-25 01:42:44
 */
@Controller
@RequestMapping("/deviceTotal")
public class DeviceTotalController extends BaseController {
    private Logger log=LoggerFactory.getLogger(this.getClass().getName());
    private String PREFIX = "/system/deviceTotal/";

    @Autowired
    private IDeviceTotalService deviceTotalService;

    /**
     * 跳转到设备统计表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "deviceTotal.html";
    }

    /**
     * 跳转到添加设备统计表
     */
    @RequestMapping("/deviceTotal_add")
    public String deviceTotalAdd() {
        return PREFIX + "deviceTotal_add.html";
    }

    /**
     * 跳转到修改设备统计表
     */
    @RequestMapping("/deviceTotal_update/{deviceTotalId}")
    public String deviceTotalUpdate(@PathVariable String deviceTotalId, Model model) {
        DeviceTotal deviceTotal = deviceTotalService.selectById(deviceTotalId).get();
        model.addAttribute("item",deviceTotal);
        LogObjectHolder.me().set(deviceTotal);
        return PREFIX + "deviceTotal_edit.html";
    }

    /**
     * 获取设备统计表列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(DeviceTotalQuery deviceTotal) {
        log.info("Query Info is {}",JSON.toJSONString(deviceTotal));
        return deviceTotalService.selectList(deviceTotal);
    }

    /**
     * 新增设备统计表
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(DeviceTotal deviceTotal) {
        deviceTotalService.insert(deviceTotal);
        return SUCCESS_TIP;
    }

    /**
     * 删除设备统计表
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam String deviceTotalId) {
        deviceTotalService.deleteById(deviceTotalId);
        return SUCCESS_TIP;
    }

    /**
     * 修改设备统计表
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(DeviceTotal deviceTotal) {
        deviceTotalService.updateById(deviceTotal);
        return SUCCESS_TIP;
    }

    /**
     * 设备统计表详情
     */
    @RequestMapping(value = "/detail/{deviceTotalId}")
    @ResponseBody
    public Object detail(@PathVariable("deviceTotalId") String deviceTotalId) {
        return deviceTotalService.selectById(deviceTotalId);
    }
}
